package action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import metier.Categorie;
import metier.Offre;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import actionform.BeanCategorie;

import dao.DAOCategorieHib;
import dao.DAOOffreHib;
 
	public class ActionCarte extends Action {
		private	DAOOffreHib	daoOffre = null;
		
		public ActionForward execute(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)
				throws Exception {
			
			String 	sCodeRegion = (String)request.getParameter("region");
			 System.out.println("BLBLBLBLBLBLBLBLBLBLBLBLB"+sCodeRegion);
			int	id_region = Integer.parseInt(sCodeRegion);
			ArrayList<Offre>	tab = daoOffre.searchRegion(id_region);
			
			/*for (int i=0; i<tab.size(); i++) {
				Categorie categorie = tab.get(i);
				BeanCategorie beanCategorie = new BeanCategorie();
				beanCategorie.setId_categorie(categorie.getId_categorie());
				beanCategorie.setNom_categorie(categorie.getNom_categorie());
				tabCategorie.add(beanCategorie);
			}*/
			request.setAttribute("LISTE_OFFRE", tab);
			
			return mapping.findForward("VueOffreRegion");
		}
		
		public void setDaoOffre(DAOOffreHib daoOffre) {
			this.daoOffre = daoOffre;
		}

		public ActionCarte() {
			// plutard, on fera une injection du DAO avec Spring...
			this.setDaoOffre(new DAOOffreHib());
		}

	}


